package com.letu.core.converter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.poi.ss.formula.functions.T;

import java.io.IOException;

public class IPageDeserializer extends StdDeserializer<IPage> {
    public static final IPageDeserializer PAGEINSTANCE = new IPageDeserializer(IPage.class);

    protected IPageDeserializer(Class<?> vc) {
        super(vc);
    }

    @Override
    public IPage deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
//        ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
//        ObjectNode root = (ObjectNode) mapper.readTree(jsonParser);
//        JsonNode records = root.findValue("records");
//        JsonNode pages = root.findValue("pages");
////        JsonNode dValue = root.findValue("d");
//        ObjectMapper om = new ObjectMapper();
//
//        try {
//            Class c = Class.forName("com.letu.venueservice.vo.ServiceProviderVO");
//            Object object = om.readValue(records.get(0).toString(), c);
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }
        JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        String s = node.toString();
        System.out.println(s);
        ObjectMapper om = new ObjectMapper();
        IPage page = om.readValue(s, IPage.class);
        return page;
    }

}
